package br.ufrgs.dbproject.dsl.sqlbatch;

public class InsertClauseCreator {

	public static String create(String selectedTableName, String[] selectedColumns, String[] selectedValues) {

		StringBuilder clauseBuilder = new StringBuilder("INSERT INTO ");

		if (selectedTableName != null) {
			clauseBuilder.append(selectedTableName);
		}

		clauseBuilder.append(" (");

		if (selectedColumns != null) {
			for (String columnName : selectedColumns) {
				clauseBuilder.append(columnName).append(",");
			}
			clauseBuilder.deleteCharAt(clauseBuilder.length() - 1);
		}

		clauseBuilder.append(") VALUES (");

		String separator = "'";
		if (selectedValues != null) {
			for (String value : selectedValues) {
				/*
				if (value.contains("'")) {
					separator = "$$";
				}
				*/
				clauseBuilder.append(separator).append(value).append(separator).append(",");
				//separator = "'";
			}
			clauseBuilder.deleteCharAt(clauseBuilder.length() - 1);
		}

		clauseBuilder.append(")");

		return clauseBuilder.toString();
	}
}